{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Practice Problem - Cryptography" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Cryptography is the study of how to make messages secret or how to read secret messages. A very simple encryption technique is called the *Caesar cipher* -- more information on it can be found [here](http://en.wikipedia.org/wiki/Caesar_cipher). The basic idea is that each letter is replaced by a letter that is a certain number of letters away, so for example if the shift was 2, then A would become C, B would become D, etc. (and Z will become B).\n", "\n", "Write a function that given a string and a shift, will produce the encrypted string for that shift. Note that the same function can be used to decrypt a message, by passing it a negative shift. \n", "\n", "The rules are: you should only accept and return lowercase letters, and spaces should not be changed.\n", "\n", "Then, decrypt the following message, which was encrypted with a shift of 13:\n", " \n", " pbatenghyngvbaf lbh unir fhpprrqrq va qrpelcgvat gur fgevat \n", " \n", "Now if you are up for a challenge, try and decrypt this **and** find the shift:\n", " \n", " gwc uivioml bw nqvl bpm zqopb apqnb\n", " \n", "Hint: there are several ways you can convert between letters and numbers. One is to use the built-in functions ``chr`` and ``ord`` (and remember you can find out more about a function by using ``?`` in IPython). Another is to set up the alphabet in a string and use item access (``[4]``) to convert from numbers to letters, and the ``index`` method to convert from letters to numbers." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Solution" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# your solution here\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.3" } }, "nbformat": 4, "nbformat_minor": 1 }